home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / games / ted5.zip / IGRABSRC.ZIP / COMP_A.ASM < prev    next >
Assembly Source File  |  1993-02-04  |  2KB  |  108 lines

  1. IDEAL
  2. MODEL    medium,C
  3. P386
  4.  
  5.  
  6. DATASEG
  7.  
  8. startdi    dw    ?
  9.  
  10. EXTRN    huffstring:DWORD
  11. EXTRN    huffbits:WORD
  12.  
  13. CODESEG
  14.  
  15. ;==================================
  16. ;
  17. ; FastHuffCompress
  18. ;
  19. ; ds:si    source
  20. ; es:di    dest
  21. ; ss:bp    (huffbits / huffstring)
  22. ;
  23. ; eax        shifted bit string
  24. ; bx        source byte
  25. ; cx        biton
  26. ; dx        bytes left to compress
  27. ;
  28. ;==================================
  29.  
  30. PROC    FastHuffCompress    source:DWORD, srclength:DWORD, dest:DWORD
  31. PUBLIC    FastHuffCompress
  32.     uses    si,di
  33. ;
  34. ; NOTE: this will not work on >64K data!
  35. ;
  36.  
  37. ;
  38. ; set up
  39. ;
  40.     mov    si,[WORD source]
  41.     mov    ax,[WORD source+2]
  42.     mov    bx,si
  43.     shr    bx,4
  44.     add    ax,bx
  45.     and    si,15
  46.     mov    ds,ax                    ; normallize ds:si
  47.  
  48.     mov    di,[WORD dest]
  49.     mov    ax,[WORD dest+2]
  50.     mov    bx,di
  51.     shr    bx,4
  52.     add    ax,bx
  53.     and    di,15
  54.     mov    es,ax                    ; normallize es:di
  55.     mov    [ss:startdi],di            ; save initial value for size calculation
  56.  
  57.     mov    edx,[srclength]
  58.     xor    al,al
  59.     mov    [es:di],al                ; clear the first byte
  60.  
  61.     xor    ebx,ebx                    ; make sure the high word of ebx is 0
  62.     xor    ecx,ecx                    ; start at bit 0
  63.  
  64. ;
  65. ; compress
  66. ;
  67.  
  68. shrinkbyte:
  69.     xor    eax,eax                    ; clear ahead of the current spot so
  70.     mov    [es:di+1],eax            ; new bits can be ORed in
  71.  
  72.     mov    bx,[si]
  73.     xor    bh,bh
  74.     inc    si
  75.  
  76.     shl    bx,2
  77.     mov    eax,[ss:huffstring+bx] ; base bit string
  78.     shl    eax,cl                    ; shift the bit string to the proper place
  79.     or    [es:di],eax                ; or it into the bit stream
  80.  
  81.     shr    bx,1
  82.     add    cx,[ss:huffbits+bx]   ; next bit string goes here
  83.     mov    ax,cx
  84.     and    cx,7
  85.     shr    ax,3
  86.     add    di,ax
  87.  
  88.     dec    dx
  89.     jnz    shrinkbyte
  90.  
  91. ;
  92. ; clean up
  93. ;
  94.     mov    ax,ss
  95.     mov    ds,ax                    ; restore C's data segment
  96.  
  97.     inc    di                        ; be sure to include the last partial byte
  98.     sub    di,[startdi]
  99.     mov    ax,di
  100.     xor    dx,dx                    ; return compressed length in dx:ax
  101.     ret
  102.  
  103. ENDP
  104.  
  105.  
  106. END
  107.  
  108.